#include "http_server.h"
#include <iostream>

// 程序入口
int main(int argc, char* argv[]) {
    int port = DEFAULT_PORT;
    
    // 从命令行参数获取端口号
    if (argc > 1) {
        try {
            port = std::stoi(argv[1]);
            if (port < 1 || port > 65535) {
                std::cerr << "Invalid port number. Using default port " << DEFAULT_PORT << std::endl;
                port = DEFAULT_PORT;
            }
        } catch (...) {
            std::cerr << "Invalid port number. Using default port " << DEFAULT_PORT << std::endl;
        }
    }
    
    // 创建并启动服务器
    try {
        HttpServer server(port);
        server.start();
    } catch (const std::exception& e) {
        std::cerr << "Server error: " << e.what() << std::endl;
        return 1;
    }
    
    return 0;
}
    